<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <input type="text" placeholder="请输入第一个数" class="inp1" />
    <input type="text" placeholder="请输入第二个数" class="inp2" />
    <button>点击求和</button>
    <input type="text" placeholder="总和为" class="inp3" />
  </body>
</html>
<script>
  var ipt1 = document.querySelector(".inp1");
  var ipt2 = document.querySelector(".inp2");
  var ipt3 = document.querySelector(".inp3");
  var btn = document.querySelector("button");
  btn.onclick = function () {
    var sum = 0;
    if (ipt1.value.trim() == "") return alert("请输入内容");
    if (ipt2.value.trim() == "") return alert("请输入内容");
    if (isNaN(ipt1.value)) return alert("请输入数字");
    if (isNaN(ipt2.value)) return alert("请输入数字");
    for (var i = ipt1.value; i <= ipt2.value; i++) {
      if (i % 2 == 0) {
        sum += i;
      }
    }
    ipt3.value = sum;
  };
</script>
